package com.example.jdt_xiazai.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.fragment.app.FragmentActivity;
import androidx.recyclerview.widget.RecyclerView;

import com.example.jdt_xiazai.R;
import com.example.jdt_xiazai.bean.FuLiBean;

import java.util.ArrayList;
import java.util.List;

public class HomeRlvAdapter extends RecyclerView.Adapter<HomeRlvAdapter.RlvViewHolder> {
    private ArrayList<FuLiBean.DataBean.DatasBean> list;
    private Context context;
    public HomeRlvAdapter(FragmentActivity activity, ArrayList<FuLiBean.DataBean.DatasBean> datasBeans) {
        this.context=activity;
        this.list=datasBeans;

    }

    public void initData(List<FuLiBean.DataBean.DatasBean> dataBeans) {
        this.list.addAll(dataBeans);
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public RlvViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.item, parent, false);
        RlvViewHolder rlvViewHolder = new RlvViewHolder(inflate);
        return rlvViewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull RlvViewHolder holder, int position) {
        holder.tl.setText(list.get(position).getChapterName());
    }

    @Override
    public int getItemCount() {
        return list.size();
    }


    public class RlvViewHolder extends RecyclerView.ViewHolder {
        TextView tl;
        public RlvViewHolder(@NonNull View itemView) {
            super(itemView);
            tl=itemView.findViewById(R.id.tl);
        }
    }
}
